package com.apex.crm.controller;

import com.apex.crm.base.BaseController;
import com.apex.crm.base.ResultInfo;
import com.apex.crm.query.DataDicQuery;
import com.apex.crm.service.DatadicService;
import com.apex.crm.vo.Datadic;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.Date;
import java.util.Map;

/**
 * @author XiaoYang
 * @version 1.0
 * @program: crm
 * @Classname DatadicController
 * @description TODO
 * @date 2021/5/3 17:05
 */
@Controller
@RequestMapping("/dataDic")
public class DatadicController extends BaseController {

    @Resource
    private DatadicService datadicService;

    @GetMapping("index")
    public String index(){
        return "dataDic/dataDic";
    }

    @GetMapping("list")
    @ResponseBody
    public Map<String,Object> queryDataDicByParams(DataDicQuery dataDicQuery){
        return datadicService.queryDatadicByParams(dataDicQuery);
    }

    @GetMapping("addOrUpdateDataDicPage")
    public String addOrUpdateSaleChancePage(Integer id, Model model){
        if(null != id){
            model.addAttribute("DataDic",datadicService.getById(id));
        }
        return "dataDic/add_update";
    }

    @PostMapping("save")
    @ResponseBody
    public ResultInfo saveDataDic(Datadic datadic){
        //保存记录
        datadicService.saveDataDic(datadic);
        return success("数据添加成功");
    }

    @PostMapping("update")
    @ResponseBody
    public ResultInfo updateDataDic(Datadic datadic){
        Datadic datadicNew=datadicService.getById(datadic.getId());
        datadicNew.setDataDicName(datadic.getDataDicName());
        datadicNew.setDataDicValue(datadic.getDataDicValue());
        datadicNew.setUpdateDate(new Date());
        datadicService.updateDataDic(datadicNew);
        return success("数据更新成功");
    }

    @PostMapping("delete")
    @ResponseBody
    public ResultInfo deleteDataDic(Integer[] ids){
        datadicService.deleteDataDic(ids);
        return success("数据删除成功!");
    }




}
